#include "l12_proto.h"

/*  for SGLI, copy pointer to geom_per_band */

void cpl1rec(l1str *dest, l1str *src) {
    dest->npix = src->npix;
    dest->length = src->length;
    dest->iscan = src->iscan;
    dest->detnum = src->detnum;
    dest->mside = src->mside;
    dest->scantime = src->scantime;
    dest->margin_s = src->margin_s;
    dest->fsol = src->fsol;
    dest->tilt = src->tilt;
    dest->alt = src->alt;

    dest->scn_fmt = src->scn_fmt;
    dest->margin_s = src->margin_s;

    memcpy(dest->data, src->data, dest->length);

    if (src->geom_per_band) {
        int32_t nbands = src->l1file->nbands;
        int32_t npix = src->npix;

        if (!dest->geom_per_band)
            init_geom_per_band(dest);

        memcpy(dest->geom_per_band->senz, src->geom_per_band->senz, npix * nbands * sizeof (float));
        memcpy(dest->geom_per_band->sena, src->geom_per_band->sena, npix * nbands * sizeof (float));
        memcpy(dest->geom_per_band->csenz, src->geom_per_band->csenz, npix * nbands * sizeof (float));
        memcpy(dest->geom_per_band->solz, src->geom_per_band->solz, npix * nbands * sizeof (float));
        memcpy(dest->geom_per_band->sola, src->geom_per_band->sola, npix * nbands * sizeof (float));
        memcpy(dest->geom_per_band->csolz, src->geom_per_band->csolz, npix * nbands * sizeof (float));
        memcpy(dest->geom_per_band->scattang, src->geom_per_band->scattang, npix * nbands * sizeof (float));
        memcpy(dest->geom_per_band->delphi, src->geom_per_band->delphi, npix * nbands * sizeof (float));
    } else {
        if (dest->geom_per_band) {
            printf("-E- cpl1rec - Should never copy from empty to allocated geo_per_band\n");
            exit(EXIT_FAILURE);
        }
    }
}
